<?php

/** PAGE NOT ALLOWED
 * Verify if user called this page through a allowed page.
 * @message: That file cannot be displayed alone.
 */
if (!isset($allowed_page)) { echo "That file cannot be displayed alone."; exit; }

class ResultSet {

  /** @private resultSet
  * Stores the resource of a record set.
  */
  private $resultSet = array();
  private $internalIndex = -1;
  private $error;

  function ResultSet() {
    //TODO: consistency validations.
  }

  /**
  *
  */
  function getRow() {
    $this->internalIndex++;
    if (isset($this->resultSet[$this->internalIndex])) {
        return $this->resultSet[$this->internalIndex];
    }
    else {
        return false;
    }
  }
  
  /**
  *
  */
  function getFirst() {
	if(!$this->isEmpty()) {
		return $this->resultSet[0];
	}
	else {
		return false;
	}
  }
  
  /**
  *
  */
  function getLast() {
  	if(!$this->isEmpty()) {
		return $this->resultSet[count($this->resultSet)-1];
	}
	else {
		return false;
	}
  }
  
  /**
  *
  */
  function getArray() {
	return $this->resultSet;
  }

  /**
  *
  */
  function fetch($resource) {
    $this->resultSet = $resource;
  }    

  /**
  *
  */
  function setError($errmsg) {
    $this->error = $errmsg;
  }
	
  /** isError function
  * Check if the most recent InterBase function call returned a Error.
  * @params - void.
  */
  public function isError() {
    return $this->error;
  }  

  /** isEmpty function
  * Returns the number of records fetched in this ResultSet.
  * @params - void.
  */
  public function isEmpty() {
  	if (count($this->resultSet) > 0) { return false; }
	else { return true; }
  }	

}
?>